import { IBaseData } from './interface';
import http from "@/utils/http";

class Base{
	protected baseUrl:string;
	//网络错误是否提示
	protected netBool:boolean;
	res={
		'code':300,
		'msg':'网络出错,请重试'
	}
	constructor(_url:string){
		this.baseUrl = _url
		this.netBool = true
	}
	//不单独处理网络问题
	NetErr(msg:string=this.res.msg){
		if(this.netBool){
			
		}
		return;
	}

	async HttpGet<T>(url:string,data:T):Promise<IBaseData>{
		try {
			return await http.Get(this.baseUrl+url,data)
		} catch (error) {
			this.NetErr()
			return error as IBaseData;
		}
	}

	async HttpDel<T>(url:string,data:T):Promise<IBaseData>{
		try {
			return await http.Del(this.baseUrl+url,data)
		} catch (error) {
			this.NetErr()
			return error as IBaseData;
		}
	}

	async HttpPost<T>(url:string,data:T):Promise<IBaseData>{
		try {
			return await http.Post(this.baseUrl+url,data)
		} catch (error) {
			this.NetErr()
			return error as IBaseData;
		}
	}

	async HttpPut<T>(url:string,data:T):Promise<IBaseData>{
		try {
			return await http.Put(this.baseUrl+url,data)
		} catch (error) {
			this.NetErr()
			return error as IBaseData;
		}
	}
}

export default Base